
export default function(url,fd = new FormData()){
    return new Promise((resolve,reject) => {

        const xhr = new XMLHttpRequest();

xhr.onreadystatechange = function(){
    if(xhr.readyState == 4){
        if(xhr.status == 200 ){
            resolve(JSON.parse(xhr.response)) ;
        }else{
            if(xhr.status == 401){
                alert('未登录或登录超时\n请重新登录')
            }else{
                alert('服务器错误'+xhr.status);
                reject(xhr.status)
            }
        }
    }
}
xhr.open('post',url +'?a='+new Date(),true)
 //设置请求头 //读取token，添加token到请求头中
 xhr.setRequestHeader('Authorization','Bearer '+ localStorage.getItem('token'))
xhr.send(fd)
    })
}
